//
//  NSDictionary+Additions.m
//  Gainko
//
//  Created by expro on 12-11-13.
//  Copyright (c) 2012年 RanCheng.gu. All rights reserved.
//

#import "NSDictionary+Additions.h"

@implementation NSDictionary (Additions)

-(NSData*) convertToData{
    
    NSMutableData *data = [[NSMutableData alloc]init];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];
    [archiver encodeObject:self forKey: @"dictionay"];
    [archiver finishEncoding];
    return data;
}

+ (id)gkDictionaryWithObjectsAndKeys:(id)firstObject , ...
{
    id curP;
    va_list list;
    NSMutableDictionary *mDic = [NSMutableDictionary dictionaryWithCapacity:1];
    //if(firstObject)
    {
        int index = 0;
        id value = firstObject;
        id key = nil;
        va_start(list, firstObject);
         while ((curP= va_arg(list, id))) {
             index++;
             if(index%2==0){
                 value = curP;
                 if(value==nil){
                     value = [NSNull null];
                 }
             }else{
                 key = curP;
                 if(key==nil){
                     key = [NSNull null];
                 }
             }
        //[mDic setObject:value forKey:key];
             if(value && key){
                 [mDic setObject:value forKey:key];
             }
        
         }
        va_end(list);
    }
    return mDic;
}

@end
